#!/usr/bin/env python
# coding=utf-8
"""
@Author  : youjia - 卞志伟
@file    : base_model.py
@contact : bianzhiwei@iyoujia.com
@time    : 2019-09-05 11:11 
@Desc    : 
@Software: PyCharm
"""
import os
import sys

# 当前文件的路径
pwd, filename = os.path.split(os.path.abspath(__file__))
# 当前文件的父路径
father_path = os.path.abspath(os.path.dirname(pwd) + os.path.sep + ".")
# 当前文件的前两级目录
grader_father = os.path.abspath(os.path.dirname(pwd) + os.path.sep + "..")
sys.path.append(pwd)
sys.path.append(father_path)
sys.path.append(grader_father)

from sqlalchemy import Column, DECIMAL, Date, DateTime, Index, String, text, BIGINT
from sqlalchemy import Text
from sqlalchemy.dialects.mysql import BIGINT, INTEGER
from sqlalchemy.dialects.mysql import TINYINT, SMALLINT,FLOAT

from report_system.other.alchemydb import db


class InvestRelationRecord(db.Model):
    __tablename__ = 'invest_relation_record'
    __table_args__ = (
        Index('idx_invest_id', 'invest_id'), Index('idx_lod_house_id', 'lod_house_id'),
    )

    id = Column(BIGINT(20), primary_key=True, comment='关联记录id')
    invest_compact_id = Column(BIGINT(20), comment='主合同ID')
    invest_id = Column(BIGINT(20), comment='投资人ID')
    invest_compact_house_id = Column(INTEGER(11), comment='租房合同ID')
    lod_house_id = Column(BIGINT(20), comment='房屋ID')
    invest_find_house_id = Column(BIGINT(20), comment='找房任务表中的ID')
    date_begin = Column(DateTime, comment='关联投资人的时间（等同于生效时间）')
    date_relieve = Column(DateTime, comment='关联合同解除的时间')
    op_id_relation = Column(BIGINT(20), comment='关联操作人')
    op_id_relieve = Column(BIGINT(20), comment='解除关联的操作人')
    create_time = Column(DateTime, comment='创建时间')
    modified_time = Column(DateTime, comment='修改时间')
    is_delele = Column(TINYINT(1), comment='是否删除，0不删除，1删除')


class Users(db.Model):
    __tablename__ = 'users'

    __table_args__ = (
        Index('idx_username', 'username'), Index('idx_mobile', 'mobile')
    )

    id = Column(BIGINT(20), primary_key=True, comment='用户id')
    username = Column(String(16), comment='用户登录名（手机号）')
    mobile = Column(String(16), comment='手机号')


class LodHouse(db.Model):
    __tablename__ = 'lod_house'

    __table_args__ = (
        Index('idx_lodge_id', 'lodge_id'), Index('idx_state_cityid', 'state', 'city_id'),
        Index('idx_city_id', 'city_id'), Index('idx_work_id', 'work_id')
    )

    id = Column(BIGINT(20), primary_key=True, comment='房屋id主键')
    title = Column(String(32), comment='房屋名称')
    title_sub = Column(String(16), comment='房屋简称')
    lodge_id = Column(BIGINT(20), comment='房源id')
    landlord_id = Column(BIGINT(20), comment='业主id')
    work_id = Column(INTEGER(11), comment='工作站id')
    service_id = Column(INTEGER(11), comment='服务中心id')
    city_id = Column(INTEGER(11), comment='城市id')
    address = Column(String(128), comment='详细地址')
    room_num = Column(SMALLINT(6), comment='卧室数')
    own_type = Column(SMALLINT(6), comment='房源所属：1-有家；2-城宿；3-斯维登；')
    item_type = Column(SMALLINT(6), comment='项目类型：1-分散式；2-集中式；')
    join_type = Column(SMALLINT(6), comment='加盟类型：0-业主加盟；1-投资人投资的房子；2-集中式房屋；3-品牌加盟房屋；4-S品牌合作房屋；5-cs模式；99-其他；')
    operate_type = Column(SMALLINT(6), comment='运营类型：0-托管；1-自营；')
    state = Column(SMALLINT(6), comment='状态：0-房屋待签约，1-加盟失败，6-BD待交付 10-筹建中，15-筹建待验收，'
                                        '20-待合并处理，30-待上线，100已上线，110已下线，120违约下线，130合同到期')
    check_house_result = Column(SMALLINT(6), comment='验收结果：0-可上线，10-上线后整改，20-整改后上线')


class InvestCompactHouse(db.Model):
    __tablename__ = 'invest_compact_house'

    __table_args__ = (
        Index('idx_city_id', 'city_id'), Index('idx_house_id', 'house_id'),
        Index('idx_invest_id', 'invest_id')
    )

    id = Column(BIGINT(20), primary_key=True, comment='投资人上房模块，房屋合同表id主键')
    state = Column(SMALLINT(6), comment='100:编辑中，0:待审核，10:审核通过，20:审核驳回，30:合同解约，40:签约失败，50:合同到期')
    invest_compact_id = Column(BIGINT(20), comment='主合同ID')
    invest_compact_no = Column(String(32), comment='主合同编号')
    invest_find_house_id = Column(BIGINT(20), comment='找房任务ID')
    city_id = Column(INTEGER(11), comment='城市ID')
    invest_id = Column(BIGINT(20), comment='投资人ID')
    business_id = Column(BIGINT(20), comment='招商经理')
    landlord_id = Column(BIGINT(20), comment='房东ID')

    lease_date_begin = Column(Date, comment='租赁开始日期（房屋承租期限，开始日期')
    lease_date_end = Column(Date, comment='租赁结束日期（房屋承租期限，结束日期')
    decorate_date_begin = Column(Date, comment='装修期开始日期')
    decorate_date_end = Column(Date, comment='装修期结束日期')
    delivery_date = Column(Date, comment='交付日期')
    rent_grow_ratio = Column(String(255), comment='每年租金，以逗号隔开，单位元')

    deposit = Column(INTEGER(11), comment='押金，单位分')
    other_fee = Column(INTEGER(11), comment='其他费用，单位分')
    agency_fee = Column(INTEGER(11), comment='中介费，单位分')
    property_fee = Column(INTEGER(11), comment='物业费，单位分')
    heating_fee = Column(INTEGER(11), comment='取暖费，单位分')
    net_fee = Column(INTEGER(11), comment='网络贷款费，单位分')
    house_id = Column(BIGINT(20), comment='房屋ID')
    house_product_type = Column(SMALLINT(6), comment='房屋产品类型(10:标准房,20:严选房)')
    cancel_type = Column(SMALLINT(6), comment='解约原因：10业主解约，20不可抗力因素，30其他，40签约失败')
    cancel_time = Column(DateTime, comment='解约日期')
    cancel_reason = Column(String(256), comment='解约原因')
    youjia_layer = Column(INTEGER(11), comment='有家人分成比例(例如30%，存储为3000)')


class InvestSettleCalendar(db.Model):
    """
    投资人日历模型
    """
    __table_args__ = {'schema': 'test2'}
    __tablename__ = 'invest_settle_calendar'
    # __table_args__ = (
    #     Index('idx_invest_id', 'invest_id'), Index('idx_lod_house_id', 'lod_house_id'),
    # )

    id = Column(BIGINT(20), primary_key=True, comment='投资人日历模型')
    invest_id = Column(BIGINT(20), comment='投资人ID')
    house_id = Column(BIGINT(20), comment='房屋ID')
    dt = Column(Date, comment='该记录所属日期')

    order_id = Column(BIGINT(20), comment='如果这天有离店订单订单则是订单id', default=0)
    check_status = Column(SMALLINT(6), comment='order_id的订单的收款核对状态（1未核对，2已通过，3已驳回，4修改待核对）', default=1)
    real_income = Column(INTEGER(11), comment='订单的实际收入/长租订单投资人收益', default=0)
    settle_fee = Column(FLOAT, comment='该笔订单该结算的金额', default=0)
    supervise_fee = Column(FLOAT, comment='该笔订单管理服务费的金额', default=0)
    mis_fee = Column(INTEGER(11), comment='在MIS中录入的其他收益', default=0)

    rent_fee = Column(FLOAT, comment='当天房租，单位分', default=0)
    agency_fee = Column(FLOAT, comment='当天中介费，单位分', default=0)
    property_fee = Column(FLOAT, comment='当天物业费，单位分', default=0)
    heating_fee = Column(FLOAT, comment='当天取暖费，单位分', default=0)
    net_fee = Column(FLOAT, comment='当天网络贷款费，单位分', default=0)

    other_fee1 = Column(INTEGER(11), comment='软装合同欠款', default=0)
    other_fee2 = Column(INTEGER(11), comment='床垫租金', default=0)
    other_fee3 = Column(INTEGER(11), comment='(软装合同欠款)剩余未还清欠款', default=0)
    other_fee4 = Column(INTEGER(11), comment='(床垫租金)剩余未还清欠款', default=0)
    other_fee14 = Column(INTEGER(11), comment='筹建房租清算', default=0)
    other_fee15 = Column(INTEGER(11), comment='解除房屋关联', default=0)

    cooperation = Column(TINYINT(1), comment='所属日期是否合作 1是 0 否', default=1)
    have_order = Column(TINYINT(1), comment='所属日期是否有入住间夜 1是 0 否', default=0)
    return_supervise_fee = Column(TINYINT(1), comment='是否返还管理服务费 1是 0 否', default=0)
    #   `own_type` smallint(6) DEFAULT '0' COMMENT '房源所属：1-有家；2-城宿；3-斯维登；',
    own_type = Column(SMALLINT(6), comment='lod_house表中的房源所属：1-有家；2-城宿；3-斯维登；', default=1)

    create_time = Column(DateTime, comment='创建时间')
    modified_time = Column(DateTime, comment='修改时间')
    is_delele = Column(TINYINT(1), comment='是否删除，0不删除，1删除', default=0)
